import { createRouter, createWebHistory } from "vue-router"
import { routes } from "./commonRoutes"
import { $Storage } from "@utils/storage.js"
import { message } from 'ant-design-vue';


const router = createRouter({
  history: createWebHistory(),
  routes,
})



router.beforeEach((to, from, next) => {
  // console.log(to.name)
  // console.log(from)
  // next()
  // if (!$Storage.getItem("jwttoken") && (to.name !== "login")) {
  //   next("/login")
  // } else {
  //   next()
  // }

  if(to.meta && to.meta.isNoLogin){
    next()
  }else{
    if($Storage.getItem("jwttoken")){
      next()
    }else{
      message.error("请登录后再进入页面")
      next("/login")
    }
  }
})

export const setUpRouter = (app) => {
  app.use(router)
}

export default router